#include "Dispatcher.h"
#include "QueueManager.h"
#include "../Core/System.h"
#include "GraderManager.h"

Dispatcher::Dispatcher()
{
}

Dispatcher::~Dispatcher()
{
    //dtor
}

void Dispatcher::ProcessRequest(Request pRequest) {
    //TODO: Log here!

    ///Getting grader ID
    int tGraderId = GraderManager::GetSingleton().GetAvailableGraderId(pRequest.Purpose);
    std::cout << "Processing request #" << pRequest.ID << " " << pRequest.Purpose << " " << tGraderId << std::endl;
}

void Dispatcher::Execute() {
    while (true) {
        while (QueueManager::GetSingleton().size() > 0) { ///Pops
            //TODO: Make sure std::queue is THREAD-SAFE!

            Request tR = QueueManager::GetSingleton().front();
            ProcessRequest(tR);
            QueueManager::GetSingleton().pop();
        }
        System::MilliSleep(500);
    }
}
